//
//  CPSCAll2CategoryRightITBTagCell.m
//  CollTest
//
//  Created by codew on 11/11/21.
//

#import "CPSCAll2CategoryRightITBTagCell.h"
#import "CPSCUIFloatLayoutView.h"
#import "CPSCAll2CategoryVC_Constants.h"

@interface CPSCAll2CategoryRightITBTagCellButton : UIButton
@property (nonatomic, strong) id<CPSCAll2CategoryRightViewUIModelProtocol> item;
@end

@implementation CPSCAll2CategoryRightITBTagCellButton
@end

/**
 每个标签 -高 30
 每个标签 左右之间的间隙 10
 每个标签 上下之间的间隙 10
 */

@interface CPSCAll2CategoryRightITBTagCell ()

@property (nonatomic, strong) CPSCUIFloatLayoutView * viewConten;

@property (nonatomic, strong) id<CPSCAll2CategoryRightViewUIModelProtocol> item;

@end

@implementation CPSCAll2CategoryRightITBTagCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.contentView addSubview:self.viewConten];
    [self.viewConten mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.left.right.bottom.mas_equalTo(0);
    }];

    
    UIView * viewLine = [[UIView alloc] init];
    viewLine.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
    [self.contentView addSubview:viewLine];
    [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
        make.right.mas_equalTo(100);
    }];

    
}

//- (void)deBugUI
//{
//    NSArray<NSString *> *suggestions = @[
//        @"公司注册",
//        @"代理记账",
//        @"许可证服务",
//        @"网站建设服务",
//        @"个人社保公积金服务",
//        @"社保公积金代理",
//        @"公司注册",
//        @"代理记账",
//        @"许可证服务",
//        @"网站建设服务",
//        @"个人社保公积金服务",
//        @"社保公积金代理"];
//
//
//    for (NSInteger i = 0; i < suggestions.count; i++) {
//
//        CPSCAll2CategoryRightITBTagCellButton *button = [[CPSCAll2CategoryRightITBTagCellButton alloc] init];
//        button.backgroundColor = [UIColor colorWithHexString:@"#EFEFF4"];
//        [button setTitleColor:[UIColor colorWithHexString:@"#555555"] forState:UIControlStateNormal];
//        [button setTitle:suggestions[i] forState:UIControlStateNormal];
//        button.titleLabel.font = [UIFont systemFontOfSize:12];
//        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
//        button.layer.cornerRadius = 2;
//        button.layer.masksToBounds = YES;
//        [self.viewConten addSubview:button];
//
//    }
//
//

//}

- (CGFloat)updateCellWithItem:(id<CPSCAll2CategoryRightViewUIModelProtocol>)item
{
    self.item = item;
             
    [self.viewConten.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    for (id<CPSCAll2CategoryRightViewUIModelProtocol> model in self.item.dataItemsSecond) {
        
        CPSCAll2CategoryRightITBTagCellButton *button = [[CPSCAll2CategoryRightITBTagCellButton alloc] init];
        button.backgroundColor = [UIColor colorWithHexString:@"#EFEFF4"];//kCPSCRandomColor;//
        [button setTitleColor:[UIColor colorWithHexString:@"#555555"] forState:UIControlStateNormal];
        [button setTitle:model.stringTitleSecond forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
        button.layer.cornerRadius = 2;
        button.layer.masksToBounds = YES;
        
        button.item = model;
        [button addTarget:self action:@selector(buttonItemClick:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [self.viewConten addSubview:button];
    }
    
    CGFloat height = [self.viewConten layoutSubviewsWithSize:CGSizeMake(KValueWidthCategoryRightUITableView, 5000) shouldLayout:YES].height;
    
    return height;
}

- (void)buttonItemClick:(CPSCAll2CategoryRightITBTagCellButton *)button
{
//    NSLog(@"stringTitleSecond: %@", button.item.stringTitleSecond);
    
    if (self.blockCategory) {
        
        self.blockCategory(button.item);
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (CPSCUIFloatLayoutView *)viewConten
{

    if (!_viewConten) {
        
        CPSCUIFloatLayoutView * view = [[CPSCUIFloatLayoutView alloc] init];
        // UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
        //        CGSizeMake(<#CGFloat width#>, <#CGFloat height#>)
        view.itemMargins = UIEdgeInsetsMake(10, 10, 0, 0);
        view.minimumItemSize = CGSizeMake(0, 30);
        _viewConten = view;
    }
    return _viewConten;
}


@end
